(function($){
	var KEY = "jforest.search";

	var Search = function(element,options){
		this.el = element;
		this.options = $.extend({
			callback:function(){}
		},options); 
		var self = this,opts = this.options;
		$(this.el).keypress(function(ev){
			  var ev=window.event||ev;
			  if(ev.keyCode==13||ev.which==13)
			  {
				opts.callback.call();
			    return false;
			   }
		});
	}

	$.fn.jfSearch = function(){
		var args = Array.prototype.slice.call(arguments, 0);
		var value = undefined;
		this.each(function () {
			var $this = $(this);
			if (args.length === 0 || typeof(args[0]) === "object") {
				opts = args.length === 0 ? {} : $.extend({}, args[0]);
				value = new Search(this,opts);$this.data(KEY,value); //创建控件
			}else if (typeof(args[0]) === "string"){
				var entity = $this.data(KEY);
                if(entity === undefined){return;}
                value = entity[args[0]].apply(entity, args.slice(1));
			}else{
				 throw 'Invalid arguments to '+KEY+' plugin: ' + args;
			}
	    });
	    return (value === undefined) ? this : value;
	};
	
	$.fn.jfSearch.Constructor = Search;
	
})(window.jQuery)